using System;
using System.Collections.Generic;
using System.Text;
using Common.Utilities;

namespace Workflows.Components
{
    /// <summary></summary>
    [Serializable]
    public class Job
    {
        #region properties
        private Guid _JobID;
        /// <summary></summary>
        public Guid JobID
        {
            get { return _JobID; }
            set { _JobID = value; }
        }

        private Guid _RunID;
        /// <summary></summary>
        public Guid RunID
        {
            get { return _RunID; }
            set { _RunID = value; }
        }

        private string _ComponentTypeName;
        /// <summary></summary>
        public string ComponentTypeName
        {
            get { return _ComponentTypeName; }
            set { _ComponentTypeName = value; }
        }

        private Guid _ComponentID;
        /// <summary></summary>
        public Guid ComponentID
        {
            get { return _ComponentID; }
            set { _ComponentID = value; }
        }
	

        //private InstructionBase _JobInstructionBase;

        //public InstructionBase JobInstructionBase
        //{
        //    get { return _JobInstructionBase; }
        //    set { _JobInstructionBase = value; }
        //}

        //private ResultBase _JobOutput;

        //public ResultBase JobOutput
        //{
        //    get { return _JobOutput; }
        //    set { _JobOutput = value; }
        //}

        private DateTime _ReceiveTime;
        /// <summary></summary>
        public DateTime ReceiveTime
        {
            get { return _ReceiveTime; }
            set { _ReceiveTime = value; }
        }

        private DateTime _SubmissionTime;
        /// <summary></summary>
        public DateTime SubmissionTime
        {
            get { return _SubmissionTime; }
            set { _SubmissionTime = value; }
        }

        private DateTime _StartTime;
        /// <summary></summary>
        public DateTime StartTime
        {
            get { return _StartTime; }
            set { _StartTime = value; }
        }

        private DateTime _FinishTime;
        /// <summary></summary>
        public DateTime FinishTime
        {
            get { return _FinishTime; }
            set { _FinishTime = value; }
        }

        private List<Guid> _Dependency;
        /// <summary></summary>
        public List<Guid> Dependency
        {
            get { return _Dependency; }
            set { _Dependency = value; }
        }

        private bool _IsFirstJob;
        /// <summary></summary>
        public bool IsFirstJob
        {
            get { return _IsFirstJob; }
            set { _IsFirstJob = value; }
        }

        private bool _IsLastJob;
        /// <summary></summary>
        public bool IsLastJob
        {
            get { return _IsLastJob; }
            set { _IsLastJob = value; }
        }

        private bool _HasError;
        /// <summary></summary>
        public bool HasError
        {
            get { return _HasError; }
            set { _HasError = value; }
        }

        private bool _Cancelled;
        /// <summary></summary>
        public bool Cancelled
        {
            get { return _Cancelled; }
            set { _Cancelled = value; }
        }

        private int _Priority;
        /// <summary></summary>
        public int Priority
        {
            get { return _Priority; }
            set { _Priority = value; }
        }

        
        private string _JobInstructionTypeName;
        /// <summary></summary>
        public string JobInstructionTypeName
        {
            get { return _JobInstructionTypeName; }
            set
            {
                this._JobInstructionTypeName = value;
            }
        }

        private string _JobOutputTypeName;
        /// <summary></summary>
        public string JobOutputTypeName
        {
            get { return _JobOutputTypeName; }
            set { this._JobOutputTypeName = value; }
        }
	

        private int _JobInstructionID;
        /// <summary></summary>
        public int JobInstructionID
        {
            get { return _JobInstructionID; }
            set { _JobInstructionID = value; }
        }

        private int _JobOutputID;
        /// <summary></summary>
        public int JobOutputID
        {
            get { return _JobOutputID; }
            set { _JobOutputID = value; }
        }
	
        #endregion

        /// <summary></summary>
        public Job()
        {
            this._JobID = Guid.Empty;
            this._RunID = Guid.Empty;
            this._ComponentID = Guid.Empty;
            this._ComponentTypeName = string.Empty;
            this._Cancelled = false;
            this._Dependency = new List<Guid>();
            this._HasError = false;
            this._IsFirstJob = false;
            this._IsLastJob = false;
            this._JobInstructionID = 0;
            this._JobOutputID = 0;
            this._Priority = 0;
            this._JobInstructionTypeName = string.Empty;
            this._JobOutputTypeName = string.Empty;
            this._ReceiveTime = TimeUtil.DbMinTime;
            this._SubmissionTime = TimeUtil.DbMaxTime;
            this._StartTime = TimeUtil.DbMinTime;
            this._FinishTime = TimeUtil.DbMaxTime;
        }

        /// <summary></summary>
        public Job(Guid runID, WorkflowComponentBase wfComponent)
        {
            this._JobID = Guid.NewGuid();
            this._RunID = runID;
            this._ComponentID = wfComponent.ComponentID;
            this._ComponentTypeName = wfComponent.GetType().FullName;
            this._Cancelled = false;
            this._Dependency=new List<Guid>();
            this._HasError = false;
            this._IsFirstJob = false;
            this._IsLastJob = false;
            this._JobInstructionID = 0;
            this._JobOutputID = 0;
            this._Priority = 0;
            this._JobInstructionTypeName = (wfComponent.Instruction == null
                                                ? string.Empty
                                                : wfComponent.Instruction.GetType().FullName);
            this._JobOutputTypeName = wfComponent.Output == null ? string.Empty : wfComponent.Output.GetType().FullName;
            this._ReceiveTime = TimeUtil.DbMinTime;
            this._SubmissionTime = TimeUtil.DbMaxTime;
            this._StartTime = TimeUtil.DbMinTime;
            this._FinishTime = TimeUtil.DbMaxTime;
        }

    }
}
